package com.me.libgdx_test;

import java.util.ArrayList;

import com.badlogic.gdx.graphics.g2d.Sprite;

public class ClassGalleryActor{
	//Texture texture = new Texture(Gdx.files.internal("data/jet.png"));
	//private ArrayList<Sprite> sprites = new ArrayList<Sprite>();
	//private Sprite selected_sprite = new Sprite();
	//private int index = 0;
	private ArrayList<ClassActorFactory> actors;
	private ClassTexturePackerLoader sprite_textures;
	Point selected_area_dims,selected_area_location;
	int squares_in_row,padding;
	/*private ClassPreviewActor preview_window;*/
	//The sprites that come in here need to be resized to distinguish between the selected and the unselected elements
	ClassGalleryActor(ClassTexturePackerLoader sprite_textures, 
			Point selected_area_dims, Point selected_area_location, 
			int squares_in_row, int padding){
		this.sprite_textures = sprite_textures;
		this.selected_area_dims = selected_area_dims;
		this.selected_area_location = selected_area_location;
		this.squares_in_row = squares_in_row;
		this.padding = padding;
		//this.preview_window = new ClassPreviewActor(preview_window);
		actors = new ArrayList<ClassActorFactory>();
	}
	public void set_references(AbstractClassDungeonObject[] classes){
		int dim = (int)(((float)(selected_area_dims.x-padding))/(float)squares_in_row);
		Point dims = new Point(dim,dim);
		Point current_location = new Point(selected_area_location);
		current_location.add(padding, padding);
		int row_count = 0;
		for(int i = 0; i < classes.length; i++){
		//for(ClassAbstractDungeonObject class_info:classes){
			actors.add(new ClassActorFactory(sprite_textures.find_by_name(classes[i].Image),
					current_location,dims,classes[i].Name,classes[i].Description,i));
			row_count++;
			if(row_count>=squares_in_row){
				current_location.move((int)(selected_area_location.x+padding), (int)(current_location.y-dims.y-padding));
				row_count = 0;
			}else{
				current_location.add((int)(dims.x+padding), 0);
			}
		}
	}
	
	public void filter_references(ArrayList<Integer> references){
		ArrayList<ClassActorFactory> valid_references = new ArrayList<ClassActorFactory>();
		for(int reference:references){
			valid_references.add(actors.get(reference));
		}
		actors = new ArrayList<ClassActorFactory>(valid_references);
	}
	
	public ArrayList<ClassActorFactory> get_actors(){
		return actors;
	}
}